
import { Ast } from "../ast";
import { RedOpenContext, RedOpenVisitor } from "./RedOpen";
export class RedOpenSuccessVisitor extends RedOpenVisitor {
    visitNode(node: Ast, ctx: RedOpenContext) {
        super.visitNode(node, ctx)
    }
    visitImageView(node: Ast, ctx: RedOpenContext) {
        if (node.id.endsWith(`close_view`) && node.clickable) {
            ctx.close = () => node.click()
        }
    }
    visitTextView(node: Ast, ctx: RedOpenContext) {
        const reg = /仅需(.*?)快币/
        if (node.id.endsWith(`bottom_line_tips_view`) && reg.test(node.text)) {
            ctx.status = `success`
            const parent = node.parent.parent
            const res = parent.textTexts().match(/仅需.*?快币(.*?)快币/)
            if (res && res.length > 0) {
                const [, count] = res;
                ctx.count = (ctx.count || 0) + parseInt(count.trim())
            }
            return;
        }
    }
}